package com.lock.demo.zookeeper.lock;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.CountDownLatch;

/**
 * @ProjectName: lock_demo
 * @Package: com.lock.demo.zookeeper.lock
 * @Author: huat
 * @Date: 2021/5/5 15:19
 * @Version: 1.0
 * 监听临时节点删除
 */
public class LockWatch implements Watcher {
    private CountDownLatch countDownLatch;

    public LockWatch(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void process(WatchedEvent watchedEvent) {
        if(watchedEvent.getType()==Event.EventType.NodeDeleted){
            countDownLatch.countDown();
        }
    }
}
